#ifndef FIXEDMODEL_H
#define FIXEDMODEL_H

#include "protocol.h"

#include <QFile>
#include <filter.h>

class FixedModel : public ProtocolTableModel
{
    Q_OBJECT
public:
    explicit FixedModel(const QString& fileName, QWidget *parent = 0);

signals:

private:
    mutable QFile file;
    int recordSize;
    int recordCount;
    int showCount;
    mutable QByteArray record;
//    QVector<qint64> records;
    mutable int cacheRow;

    void loadRecord(int row) const;

    // QAbstractItemModel interface
public:
    int rowCount(const QModelIndex &parent) const;
    int columnCount(const QModelIndex &parent) const;
    QVariant data(const QModelIndex &index, int role) const;
    void fetchMore(const QModelIndex &parent);
    bool canFetchMore(const QModelIndex &parent) const;
    QVariant headerData(int section, Qt::Orientation orientation, int role) const;

    // ProtocolTableModel interface
public:
    qint64 position(const QModelIndex &index);
    QModelIndex locate(qint64 pos);
    bool deleteRows(const QString &fileName, const QModelIndexList &rows);
    bool deleteColumns(const QString &fileName, const QModelIndexList &cols);
    bool saveRows(const QString &fileName, const QModelIndexList &rows);
    bool saveColumns(const QString &fileName, const QModelIndexList &cols);
    bool supportFilter(const QModelIndex &index);
    void filter(const QModelIndex &index);
    int frameSize(void) { return recordSize; }
    void setFrameSize(int size);
};

#endif // FIXEDMODEL_H
